﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Diagnostics;

namespace BattleforgeAssault
{
    public partial class LocationView : UserControl
    {
        public Location Location { get { return DataContext as Location; } }

        public LocationView()
        {
            InitializeComponent();
        }

        private void OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement element = sender as FrameworkElement;
            Location location = element.DataContext as Location;
            Game game = location.Game;
            if (game.State == Types.States.Targeting)
            {
                if (game.Controller.CurrentTargets.Contains(location))
                {
                    game.Controller.CurrentTargets.Remove(location);
                    Select(false);
                }
                else
                {
                    game.Controller.CurrentTargets.Add(location);
                    Select(true);
                }
            }
        }

        /// <summary>
        /// Selects this location.
        /// </summary>
        /// <param name="value">True to select, false to unselect.</param>
        public void Select(bool value)
        {
            if (value == true)
            {
                outline.BorderThickness = new Thickness(4);
                Util.PlayDoubleAnimation(0, -16, 0.5, translation, TranslateTransform.YProperty);
            }
            else if (value == false)
            {
                outline.BorderThickness = new Thickness(0);
                Util.PlayDoubleAnimation(-16, 0, 0.5, translation, TranslateTransform.YProperty);
            }
        }

        /// <summary>
        /// Dims this location (to show an invalid target).
        /// </summary>
        /// <param name="value">True to dim, false to undim.</param>
        public void Dim(bool value)
        {
            if (value) { Util.PlayDoubleAnimation(0, .4, .5, dimmer, OpacityProperty); }
            else { Util.PlayDoubleAnimation(.4, 0, .5, dimmer, OpacityProperty); }
        }
    } // LocationView class
} // Namespace
